home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.5 / Examples / Icon / IdentifyHook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-30  |  3.1 KB  |  173 lines

  1. /*
  2.  * $Id$
  3.  *
  4.  * :ts=4
  5.  *
  6.  * COPYRIGHT:
  7.  *
  8.  *   Unless otherwise noted, all files are Copyright (c) 1999 Amiga, Inc.
  9.  *   All rights reserved.
  10.  *
  11.  * DISCLAIMER:
  12.  *
  13.  *   This software is provided "as is". No representations or warranties
  14.  *   are made with respect to the accuracy, reliability, performance,
  15.  *   currentness, or operation of this software, and all use is at your
  16.  *   own risk. Neither Amiga nor the authors assume any responsibility
  17.  *   or liability whatsoever with respect to your use of this software.
  18.  *
  19.  */
  20.  
  21. #include <datatypes/datatypes.h>
  22.  
  23. #include <dos/dosextens.h>
  24. #include <dos/dosasl.h>
  25.  
  26. #include <exec/memory.h>
  27.  
  28. #include <workbench/workbench.h>
  29.  
  30. #include <clib/exec_protos.h>
  31. #include <clib/datatypes_protos.h>
  32. #include <clib/utility_protos.h>
  33. #include <clib/dos_protos.h>
  34.  
  35. #include <pragmas/exec_sysbase_pragmas.h>
  36. #include <pragmas/datatypes_pragmas.h>
  37. #include <pragmas/utility_pragmas.h>
  38. #include <pragmas/dos_pragmas.h>
  39.  
  40. #include <string.h>
  41.  
  42. /****************************************************************************/
  43.  
  44. extern struct Library * DataTypesBase;
  45. extern struct Library * SysBase;
  46. extern struct Library * DOSBase;
  47. extern struct Library * IconBase;
  48.  
  49. /****************************************************************************/
  50.  
  51. #include <workbench/icon.h>
  52. #include <clib/icon_protos.h>
  53. #include <pragmas/icon_pragmas.h>
  54.  
  55. /****************************************************************************/
  56.  
  57. struct DiskObject * __saveds __asm
  58. IdentifyHookFunc(
  59.     register __a0 struct Hook *                h,
  60.     register __a2 APTR                        unused,
  61.     register __a1 struct IconIdentifyMsg *    iim)
  62. {
  63.     struct DiskObject * icon = NULL;
  64.     struct DataType * dtn;
  65.  
  66.     dtn = ObtainDataTypeA(DTST_FILE,(APTR)iim->iim_FileLock,NULL);
  67.     if(dtn != NULL)
  68.     {
  69.         const struct DataTypeHeader * dth = dtn->dtn_Header;
  70.         STRPTR type;
  71.  
  72.         switch(dth->dth_GroupID)
  73.         {
  74.             case GID_SYSTEM:
  75.  
  76.                 type = "system";
  77.                 break;
  78.  
  79.             case GID_TEXT:
  80.  
  81.                 type = "text";
  82.                 break;
  83.  
  84.             case GID_DOCUMENT:
  85.  
  86.                 type = "document";
  87.                 break;
  88.  
  89.             case GID_SOUND:
  90.  
  91.                 type = "sound";
  92.                 break;
  93.  
  94.             case GID_INSTRUMENT:
  95.  
  96.                 type = "instrument";
  97.                 break;
  98.  
  99.             case GID_MUSIC:
  100.  
  101.                 type = "music";
  102.                 break;
  103.  
  104.             case GID_PICTURE:
  105.  
  106.                 type = "picture";
  107.                 break;
  108.  
  109.             case GID_ANIMATION:
  110.  
  111.                 type = "animation";
  112.                 break;
  113.  
  114.             case GID_MOVIE:
  115.  
  116.                 type = "movie";
  117.                 break;
  118.  
  119.             default:
  120.  
  121.                 type = NULL;
  122.                 break;
  123.         }
  124.  
  125.         ReleaseDataType(dtn);
  126.  
  127.         if(type != NULL)
  128.         {
  129.             icon = GetIconTags(NULL,
  130.                 ICONGETA_GetDefaultName,type,
  131.             TAG_MORE,iim->iim_Tags);
  132.         }
  133.     }
  134.  
  135.     return(icon);
  136. }
  137.  
  138. struct Hook IdentifyHook =
  139. {
  140.     {NULL},
  141.     (HOOKFUNC)IdentifyHookFunc
  142. };
  143.  
  144. /****************************************************************************/
  145.  
  146. int
  147. main(int argc,char **argv)
  148. {
  149.     if(IconBase->lib_Version < 44)
  150.     {
  151.         Printf("Could not open icon.library V44\n");
  152.         goto out;
  153.     }
  154.  
  155.     IconControl(NULL,
  156.         ICONCTRLA_SetGlobalIdentifyHook,&IdentifyHook,
  157.     TAG_DONE);
  158.  
  159.     Printf("Icon identification hook installed; ^C to remove.");
  160.     Flush(Output());
  161.     Wait(SIGBREAKF_CTRL_C);
  162.  
  163.     IconControl(NULL,
  164.         ICONCTRLA_SetGlobalIdentifyHook,NULL,
  165.     TAG_DONE);
  166.  
  167.     Printf(" Done.\n");
  168.  
  169.  out:
  170.  
  171.     return(0);
  172. }
  173.